import express, { Request, Response } from "express"
import { LoggedInRequest } from "../../types"
import { checkError } from "../../utils/token"
import { CommondityManageCtx } from "../../context/CommondityManageCtx"
import { SearchListQuery } from "@Tea/model"

const searchRouter = express.Router()

searchRouter.get('/', async (req: LoggedInRequest, res: Response) => {
  try {
    const query = req.query as any as SearchListQuery
    const data = await CommondityManageCtx.getInstance().searchList(query)

    res.send({
      code: 1,
      msg: '查询成功',
      data: data
    })

  } catch (ex) {
    res.status(500).send({
      code: 0,
      msg: checkError(ex)
    })
  }
})

export default searchRouter